package metier;
import java.util.List;


import org.hibernate.Session;
import org.hibernate.Transaction;
import dao.DocenteteDAO;
import persistence.BaseDAO;


public class DocenteteManager {
	

	public static List getDocentetes(int idDomaine,int type,int start, int limit, String colFiltre, String valFiltre) throws Exception {
		Session session = BaseDAO.getInstance().openSession();
		Transaction tx = null;
		try {
			if (idDomaine != 0)
			{
				tx = session.beginTransaction();
				String rqtArticle="from Docentete d WHERE d.idDomaine="+idDomaine;
				System.out.println(type);
				if(type!=0)
				{
					rqtArticle+=" AND d.idType = "+type;
				}		
				if((valFiltre != null) &&  (valFiltre.isEmpty()==false) && (valFiltre != "%"))
				{
					rqtArticle+=" AND d."+colFiltre+" like '"+valFiltre+"'";
				}			
				List list  = DocenteteDAO.getListDocentete(rqtArticle,session,start,limit);
				session.close();
				return list;
			}else
				return null;
		} catch (Exception e) {
			if (tx != null) {
				tx.rollback();
			}
			e.printStackTrace();
			throw new Exception(e.getMessage());
		}
		
	}
}
